package Waya::App::NewGoGoD;

use warnings;
use strict;

our $VERSION = '0.1';

use base 'Waya::App::FileIterator';


# Takes a file with a name like '800419-1-top' and renames it according to the
# GoGoD standard (1980-04-19.sgf), and set the game comment to "Page 1 top"
# and the date accordingly. Also accepts a letter after the date to
# distinguish multiple games recorded on the same day (e.g., '800419a-1-top').

sub process_game {
    my $self = shift;
    if ($self->filename =~ /(\d\d)(\d\d)(\d\d)(\w*)-(\d+)-(top|bot)\.sgf/) {
        my ($year, $month, $day, $id, $page, $location) = ($1, $2, $3, $4, $5, $6);

        $year = sprintf "%s%s", ($year < 10 ? '20' : '19'), $year;

        my $date = sprintf '%04d-%02d-%02d' => $year, $month, $day;
        
        my $info = $self->game->game_info_node;
        $location = 'bottom' if $location eq 'bot';
        $info->{GC} = "Page $page $location";
        $info->{DT} = $date;

        
        $self->filename("$date$id.sgf");
    } else {
        warn sprintf "can't parse filename [%s]\n", $self->filename;
        $self->clear_should_write;
    }
}


1;
